/**
 * 
 */
package com.dingjian.meal.controller;

import java.util.ArrayList;
import java.util.Collection;

import javax.annotation.Resource;

import net.sf.json.JSONArray;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.dingjian.base.service.BaseService;
import com.dingjian.base.util.StringUtils;
import com.dingjian.framework.base.controller.EditController;
import com.dingjian.meal.model.Dishes;
import com.dingjian.meal.model.Restaurant;
import com.dingjian.meal.service.RestaurantService;

/**
 *
 * @author FengMy
 * @since 2012-6-8
 */
@Controller
@RequestMapping(value="meal/restaurant/*")
public class RestaurantEditController extends EditController {
	@Resource(name="restaurantService")
	private RestaurantService restaurantService;
	@Override
	protected BaseService<Restaurant> getService() {
		return restaurantService;
	}
	
	@Override
	protected Object getSubmitEntity() {
		Restaurant entity = (Restaurant) super.getSubmitEntity();
		String entryJson = getString("entryJson");
		if(!StringUtils.isEmpty(entryJson)){
			Collection<Dishes> tmp = JSONArray.toCollection(JSONArray.fromObject(entryJson), Dishes.class);
			entity.setDishes(new ArrayList<Dishes>(tmp));
		}
		return entity;
	}

	@Override
	protected Class getSubmitClass() {
		return Restaurant.class;
	}
}
